package com.danco.planner.essences.arraylists;

import java.util.ArrayList;
import java.util.Date;

import com.danco.planner.essences.Lecture;
import com.danco.planner.sortings.sortby.SortByDate;
import com.danco.planner.sortings.sortby.SortByName;


public class LecturesList extends ArrayList<Lecture> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//In truth, I can not imagine why i need this ID
	
	public void sortByName() {
		this.sort(new SortByName());
	}
	public void sortByDate() {
		this.sort(new SortByDate());
	}
	
	public LecturesList getLecturesInDate(Date date) {
		
		long day = date.getTime() / (1000 * 3600 * 24);
		
		LecturesList result = new LecturesList();
		
		for (Lecture lecture : this) {
			long lectureDay = lecture.getDate().getTime() / (1000 * 3600 * 24);
			if (day == lectureDay) result.add(lecture);
		}
		
		return result;
	}

	@Override
	public String toString() {
		
		StringBuilder stb = new StringBuilder();
		for (Lecture lecture : this) {
			stb.append(lecture.toString() + "\n");
		}
		stb.deleteCharAt(stb.length()-1);
		return stb.toString();
	}
}
